<template>
	<page-meta :root-font-size="getRootFontSize()"></page-meta>	
	<view class="">
		<view class="topBox">
			<view class="status_bar"></view>
			<uni-nav-bar
				style="width: 750rpx; height: 44px;"
				@clickRight="showSetUp"
				@clickLeft="goHome"
				color="#FDFDFD"
				:border="false"
				:shadow="false"
				background-color="#F1F1F1"
			>
				<view class="titleImg"><image style="width: 100%; height: 100%;" mode="scaleToFill" src="/static/icon/logo_ctw@3x.png"></image></view>
				<view slot="left">
					<view class="leftIconBox"><uni-icons type="arrowleft" color="#000" size="18"></uni-icons></view>
				</view>
				<view slot="right"><uni-icons type="bars" color="#7F7F7F" size="28"></uni-icons></view>
			</uni-nav-bar>
		</view>
		<view class="zhuti" :style="{ marginTop: topBar }">
			<view class="imageTopBox"><image style="width: 100%; height: 100%;" mode="scaleToFill" src="/static/icon/OneDrive_10_11-16-2021/2x/pic_banner01@2x.png"></image></view>
			<view class="tabTopBox">
				<view
					class="tabTopItem"
					:style="{ margin: index === 1 ? '0 1px' : 0, backgroundColor: tabBg === item.id ? '#CD001B' : '#7f7f7f' }"
					@tap="tabbtn(item)"
					v-for="(item, index) in tabList"
					:key="index"
				>
					{{ item.text }}
				</view>
			</view>
			<product-introduction-one v-if="tabBg === 1"></product-introduction-one>
			<product-introduction-two v-else-if="tabBg === 2"></product-introduction-two>
			<product-introduction-three v-else></product-introduction-three>
			<!-- <view :style="{ height: windowHeight + 'px' }"></view> -->
		</view>
		<!-- 设置 -->
		<uni-popup ref="SetUpPopup" type="center" :animation="false"><set-up-pages ref="showPopup" @closePopUp="closePopUp" /></uni-popup>
		<!-- 退出 -->
		<sign-out ref="signOutBox" />
		<!-- 底部菜单 -->
		<bottom-pages></bottom-pages>
	</view>
</template>

<script>
import setUpPages from '@/pages/setUpPages/index.vue';
import signOut from '@/pages/setUpPages/signOut.vue'; // 退出登录
import bottomPages from '@/pages/home/bottomPages.vue'; // 底部
import productIntroductionOne from './productIntroductionOne.vue';
import productIntroductionTwo from './productIntroductionTwo.vue';
import productIntroductionThree from './productIntroductionThree.vue';
import baseFont from '@/utils/baseFont.js';

export default {
	extends: baseFont,
	data: function() {
		return {
			topBarHeight: 0,
			windowHeight: 0,
			back_k: 0, // 物理返回
			popupIsShow: false, // 打开设置的标识
			signOutShow: false, // 退出登录
			tabBg: 1,
			// tabList: [
			// 	{
			// 		text: this.$t('productIntroduction').ctwfont1,
			// 		id: 1
			// 	},
			// 	{
			// 		text: this.$t('productIntroduction').ctwfont7,
			// 		id: 2
			// 	},
			// 	{
			// 		text: this.$t('productIntroduction').ctwfont9,
			// 		id: 3
			// 	}
			// ]
		};
	},
	onLoad(option) {
		const { pages } = option;
		this.tabBg = Number(pages) || 1;
		// 拦截物理返回键
		this.goBackBox();
	},
	onUnload() {
		uni.$off('goBack_k', this.goBackBox2);
	},
	onHide() {
		this.$refs.SetUpPopup.close();
		this.popupIsShow = false;
		this.$refs.signOutBox.close();
	},
	created() {
		const that = this;
		uni.getSystemInfo({
			success(res) {
				that.topBarHeight = res.statusBarHeight;
				that.windowHeight = res.windowHeight;
			}
		});
	},
	components: { setUpPages, signOut, bottomPages, productIntroductionOne, productIntroductionTwo, productIntroductionThree },
	computed: {
		topBar() {
			let num = 0;
			num = this.topBarHeight + 44; // 44是顶部高度
			return num + 'px';
		},
		i18n() {
			return this.$t('productIntroduction');
		},
		tabList() {
			const arr = [
				{
					text: this.$t('productIntroduction').ctwfont1,
					id: 1
				},
				{
					text: this.$t('productIntroduction').ctwfont7,
					id: 2
				},
				{
					text: this.$t('productIntroduction').ctwfont9,
					id: 3
				}
			];
			return arr;
		}
	},
	methods: {
		goBackBox() {
			// const that = this;
			uni.$on('goBack_k', this.goBackBox2);
		},
		goBackBox2(data) {
			this.back_k < 0 ? (this.back_k = 0) : (this.back_k = this.back_k);
			if (data) {
				if (this.popupIsShow) {
					this.$refs.SetUpPopup.close();
					this.popupIsShow = false;
				} else if (this.signOutShow) {
					this.$refs.signOutBox.close();
					this.signOutShow = false;
				} else {
					let main = plus.android.runtimeMainActivity();
					if (this.back_k > 0) {
						this.back_k = 0;
						return main.moveTaskToBack(false);
						// return plus.runtime.quit();
					} else {
						const pages = getCurrentPages();
						if (pages.length === 1) {
							this.back_k++;
							setTimeout(() => {
								this.back_k--;
							}, 1000);
							// #ifdef APP-PLUS
							uni.redirectTo({
								url: '/pages/home/index'
							});
							// #endif
							// #ifdef H5
							this.$Router.push('/pages/home/index');
							// #endif
							// uni.showToast({
							// 	title: '再按一次退出应用',
							// 	icon: 'none',
							// 	duration: 1000
							// });
						}
					}
				}
			}
		},
		// 返回home
		goHome() {
			// #ifdef APP-PLUS
			uni.redirectTo({
				url: '/pages/home/index'
			});
			// #endif
			// #ifdef H5
			this.$Router.push('/pages/home/index');
			// #endif
		},
		// 打开设置
		showSetUp() {
			this.$refs.SetUpPopup.open('right');
			this.popupIsShow = true;
		},
		// 关闭设置
		closePopUp(val) {
			if (val) {
				this.$refs.SetUpPopup.close();
				this.popupIsShow = false;
			} else {
				this.$refs.SetUpPopup.close();
				this.popupIsShow = false;
				this.$refs.signOutBox.open();
				this.signOutShow = true;
			}
		},
		// 点击tab
		tabbtn(val) {
			this.tabBg = val.id;
		}
	}
};
</script>

<style lang="scss" scoped>
.titleImg {
	width: 60px;
	height: 30px;
	margin: 0 auto;
	border-radius: 50%;
	overflow: hidden;
}
.leftIconBox {
	width: 25px;
	height: 25px;
	background-color: #fff;
	border-radius: 50%;
	display: flex;
	justify-content: center;
	align-items: center;
	margin-left: 15px;
}
.topBox {
	position: fixed;
	top: 0;
	left: 0;
	z-index: 10;
	// 顶部部分
	.status_bar {
		height: var(--status-bar-height);
		background-color: #f1f1f1;
		width: 100%;
	}
}
.zhuti {
	.imageTopBox {
		width: 100%;
		height: 100px;
	}
	.tabTopBox {
		display: flex;
		justify-content: space-between;
		align-items: center;
		.tabTopItem {
			flex: 1;
			text-align: center;
			height: 30px;
			line-height: 30px;
			color: #e3e3e3;
			font-size: $uni-font-size-custom-b;
			background-color: #7f7f7f;
			overflow: hidden;
			text-overflow: ellipsis;
			display: -webkit-box;
			-webkit-line-clamp: 1;
			overflow: hidden;
			-webkit-box-orient: vertical;
		}
	}
}
// .bottomBox {
// 	position: fixed;
// 	bottom: 0;
// 	width: 100%;
// }
</style>
